/**
 * 用户表js
 */

$(function() {
	initialPage();
	getGrid();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {
			height : $(window).height() - 56
		});
	});
}

function getGrid() {
	$('#dataGrid').bootstrapTableEx({
		url : '../../sys/tuser/list?wxType=2&_' + $.now(),
		height : $(window).height() - 56,
		queryParams : function(params) {
			params.name = vm.keyword;
			return params;
		},
		columns : [ {
			checkbox : true
		}, {
			field : "createTime",
			title : "创建时间",
			width : "100px"
		}, {
			field : "userName",
			title : "用户名",
			width : "100px"
		},{
			field : "name",
			title : "名称",
			width : "100px"
		}, {
			field : "contacts",
			title : "联系人",
			width : "100px"
		}, {
			field : "telephone",
			title : "电话",
			width : "100px"
		}, {
			field : "province",
			title : "省",
			width : "100px"
		}, {
			field : "city",
			title : "市",
			width : "100px"
		}, {
			field : "area",
			title : "区",
			width : "100px"
		}, {
			field : "address",
			title : "地址",
			width : "100px"
		},{
			field : "status",
			title : "可用",
			width : "60px",
			align : "center",
			formatter : function(value, row, index) {
				if (value == 1) {
					return '<i class="fa fa-toggle-on"></i>';
				}else {
					return '<i class="fa fa-toggle-off"></i>';
				}
			}
		}, {
			field : "type",
			title : "用户类型",
			width : "60px",
			align : "center",
			formatter : function(value, row, index) {
				if (value == 1) {
					return '<span>个人</span>';
				}else if (value == 2) {
					return '<span>个体</span>';
				}else {
					return '<span>企业</span>';
				}
			}
		}, {
			field : "auditStatus",
			title : "状态",
			width : "60px",
			align : "center",
			formatter : function(value, row, index) {
				if (value == 1) {
					return '<span>未认证</span>';
				}else if (value == 2) {
					return '<span>认证失败</span>';
				}else {
					return '<span>认证成功</span>';
				}
			}
		}]
	})
}

var vm = new Vue({
	el : '#dpLTE',
	data : {
		keyword : null
	},
	methods : {
		load : function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		save : function() {
			dialogOpen({
				title : '新增用户表',
				url : 'base/tuser/add.html?_' + $.now(),
				width : '420px',
				height : '350px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections');
			if (checkedRow(ck)) {
				dialogOpen({
					title : '编辑用户表',
					url : 'base/tuser/edit.html?_' + $.now(),
					width : '500px',
					height : '630px',
					success : function(iframeId) {
						top.frames[iframeId].vm.user.id = ck[0].id;
						top.frames[iframeId].vm.setForm();
					},
					yes : function(iframeId) {
						top.frames[iframeId].vm.acceptClick();
					}
				});
			}
		},
		remove : function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
			if (checkedArray(ck)) {
				$.each(ck, function(idx, item) {
					ids[idx] = item.id;
				});
				$.RemoveForm({
					url : '../../sys/tuser/remove?_' + $.now(),
					param : ids,
					success : function(data) {
						vm.load();
					}
				});
			}
		},
		disable: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];	
			if(checkedArray(ck)){
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});
				$.ConfirmForm({
					msg: '您是否要禁用所选账户吗？',
					url: '../../sys/tuser/disable?_' + $.now(),
			    	param: ids,
			    	success: function(data) {
			    		vm.load();
			    	}
				});
			}
		},
		enable: function() {
			var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];	
			if(checkedArray(ck)){
				$.each(ck, function(idx, item){
					ids[idx] = item.id;
				});
				$.ConfirmForm({
					msg: '您是否要启用所选账户吗？',
					url: '../../sys/tuser/enable?_' + $.now(),
			    	param: ids,
			    	success: function(data) {
			    		vm.load();
			    	}
				});
			}
		},
	}
})